import java.util.Scanner;

/**
 * @author yexiebao
 * @date 2025/5/13
 * 思路：
 * 1.先找到中间位置，然后判断中间位置的值和目标值大小关系，然后缩小范围，缩小范围时，要考虑边界情况
 * 2.如果中间位置的值比目标值小，则目标值在右边，缩小右边范围
 * 3.如果中间位置的值比目标值大，则目标值在左边，缩小左边范围
 * 4.如果中间位置的值等于目标值，则找到目标值，返回位置
 *
 *
 */
public class BinarySearch {
    //两边闭合
    public static int binarySearch(int[] arr,int target){
        int left = 0;
        int right = arr.length-1;
        while(left <= right){
            int mid = (left + right)/2;
            if(arr[mid]==target){
                return mid;
            }
            if(arr[mid] < target){
                left = mid + 1;
            }
            if(arr[mid] > target){
                right = mid -1;
            }
        }
        return -1;
    }

    //左闭右开
    public static int binarySearch2(int[] arr,int target){
        int left = 0;
        int right = arr.length;
        while(left < right){
            int mid = (left + right)/2;
            if(arr[mid] == target){
                return mid;
            }
            if (arr[mid]>target){
                right = mid;
            }
            if(arr[mid]<target){
                left = mid+1;
            }
        }
        return -1;
    }
    //ACM模式
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int target = scanner.nextInt();
        int[]nums = new int[n];
        for(int i = 0;i<n;i++){
            nums[i] = scanner.nextInt();
        }
        System.out.println(binarySearch(nums, target));
    }
}